<template>
  <!-- 商城设置  修改店铺信息 -->
  <div class="user-set-box radius" v-if="shopInfo">

    <!-- 头像 -->
    <!-- <div class="head-img" v-if="checkPermi(['shopCenter:editInfo'])">
        <el-upload :action="uploadImgUrl" :show-file-list="false" list-type="picture-card" :limit="1" :on-success="handleAvatarSuccess">
          <div class="btn font12">更换LOGO</div>
          <img :src="shopInfo.avatar" alt="" />
        </el-upload>
      </div>
      <div class="head-img" v-else>
        <img :src="shopInfo.avatar" alt="" />
      </div> -->
    <!-- 提现账号 -->
    <!-- <div class="form-box">
      <div class="tit flex alc">
        <formSubTitVue :title="'收款账户'" :tip="''"></formSubTitVue>
        <div class="edit-btn font12" v-if="userInfo.userId == shopInfo.adminId">
          <el-button size="mini" type="primary" @click="addBackcard">添加</el-button>
        </div>
        <div v-else style="color:red">只有店铺管理员才能添加收款账户</div>

      </div>
      <div class="my_cards flex">
        <div class="item flex" v-for="item in cardsList" :key="item.id">
          <span class="icon">
            <img v-if="item.collectionType==2" src="https://imgage.maimaihao.com/yuduhulian/erp/static/icon/zfblogo.png" alt="">
            <img v-if="item.collectionType==3" src="https://imgage.maimaihao.com/yuduhulian/erp/static/icon/bankcard.png" alt="">
          </span>
          <span class="account">{{item.collectionAccount}}</span>
          <span class="name">{{item.collectionUserName}}</span>
          <el-button v-if="userInfo.userId == shopInfo.adminId" type="text" @click="delItem(item.id)">删除</el-button>
        </div>
      </div>
    </div> -->

    <el-dialog title="修改店铺资料" append-to-body :visible.sync="centerDialogVisible" width="900px" center>
      <div class="form-box">
        <el-form ref="form" :rules="rules" :model="form" :inline="true" label-width="110px">
          <el-form-item label="店铺LOGO:" prop="avatar">
            <uploadImageOne v-model="form.avatar" @change="avatarChange"></uploadImageOne>
          </el-form-item><br />
          <el-form-item label="店铺名称:" prop="tenantName">
            <el-input size="small" v-model="form.tenantName" placeholder="请输入店铺名称" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <el-form-item label="店铺域名:">
            <span>{{ form.domain }}</span>
          </el-form-item>
          <el-form-item label="域名备案号:">
            <el-input size="small" v-model="form.beian" placeholder="请填写域名对应的工信部备案号" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <el-form-item label="版权描述:">
            <el-input size="small" v-model="form.banquan" placeholder="请填写网站版权描述，展示在自营商城底部" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <br />
          <!-- <el-form-item label="企业全称:">
            <el-input size="small" v-model="form.enterpriseName" placeholder="请输入企业全称" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <el-form-item label="纳税人识别号:">
            <el-input size="small" v-model="form.businessLicenseNumber" placeholder="请输入纳税人识别号" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <el-form-item label="店铺地址:">
            <el-input size="small" v-model="form.otherShopAddress" placeholder="淘宝、PDD等电商平台店铺地址" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <br />
          <el-form-item label="绑定微信号:">
            <el-input size="small" v-model="form.wechatNumber" placeholder="请输入微信号" :disabled="!isEditInfo"></el-input>
          </el-form-item>
          <el-form-item label="绑定支付宝:">
            <el-input size="small" v-model="form.alipayNumber" placeholder="请输入支付宝" :disabled="!isEditInfo"></el-input>
          </el-form-item> -->
          <el-form-item label="联系人微信" prop="lianxiweixin">
            <el-input v-model="form.lianxiweixin" placeholder="请输入联系人微信" />
          </el-form-item>
          <el-form-item label="联系人手机" prop="lianxishouji">
            <el-input v-model="form.lianxishouji" placeholder="请输入企业支付宝号" />
          </el-form-item>
          
          <!-- <div style="color: #999;">
            号商联系你提号时展示
          </div> -->
          <br />
          <el-form-item label="营业执照:">
            <uploadImageOne :disabled="!isEditInfo" v-model="form.businessLicenseImg" @change="businessLicenseImgChange"></uploadImageOne>
          </el-form-item><br />
          <el-form-item label="店铺简介:">
            <el-input size="small" type="textarea" rows="12" style="width:510px" v-model="form.introduction" placeholder="请输入店铺简介，此简介会展示在用户端" :disabled="!isEditInfo"></el-input>
          </el-form-item><br />
          <div class="btn-box" v-if="isEditInfo">
            <el-button size="small" @click="cancelEdit">取消</el-button>
            <el-button size="small" type="primary" @click="editUserInfo">确认修改</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!-- <payBZJ ref="payBZJ"></payBZJ>
    <BZJmingxi ref="BZJmingxi"></BZJmingxi>
    <tixian ref="tixian" @tixianover="getTixianing"></tixian>
    <chongzhi ref="chongzhi"></chongzhi> -->
    <!-- <userInfoSure ref="userInfoSure"></userInfoSure> -->
    <!-- <authDialog ref="authDialog"></authDialog>
    <addBankcardDialog ref="addBankcardDialog" @success="getList" @openAuthDialog="openAuth"></addBankcardDialog>
    <haibaoDialog ref="haibaoDialog"></haibaoDialog> -->
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { tenantqiyerenzheng } from "@/api/system/user";
import { editShop } from "@/api/system/shopManage";
import formSubTitVue from "@/views/tenantPages/components/formSubTit.vue";
// import payBZJ from "@/views/tenantPages/moneys/components/payBZJ.vue";
// import BZJmingxi from "@/views/tenantPages/moneys/components/BZJmingxi";
// import tixian from "@/views/tenantPages/moneys/components/tixian.vue";
// import chongzhi from "../../moneys/components/chongzhijifen.vue";
// import authDialog from "./authDialog";
import myMoneyApi from "@/api/financeCenter/myMoney.js";
// import addBankcardDialog from "./addBankcardDialog.vue";
// import haibaoDialog from "./haibaoDialog.vue";

// import userInfoSure from "../../components/userInfoSure.vue";
export default {
  name: "",
  components: {
    formSubTitVue,
    // payBZJ,
    // BZJmingxi,
    // tixian,
    // chongzhi,
    // userInfoSure,
    // authDialog,
    // addBankcardDialog,
    // haibaoDialog,
  },
  data() {
    return {
      centerDialogVisible: false,
      isEditName: false,
      isEditInfo: false,
      form: {
        realName: "",
      },
      uploadImgUrl: "",
      rules: {
        // realName: [
        //     { required: true, message: '请输入姓名', trigger: 'blur' }
        //   ],
      },
      BZJmoney: null,
      BZJdes: ``,
      cardsList: [],
      TIXIANING: "", //提现中的记录
    };
  },
  computed: {
    ...mapGetters(["userInfo", "shopInfo"]),
  },
  watch: {
    shopInfo: {
      handler(newVal) {
        if (newVal) this.form = JSON.parse(JSON.stringify(newVal));
      },
      immediate: true,
      deep: true,
    },
  },
  created() {
    // this.getBZJ()
    // this.getTixianing();
    // this.getList();
    this.uploadImgUrl = process.env.VUE_APP_BASE_API + "/upload/image";
  },
  methods: {
    open() {
      this.centerDialogVisible = true;
      this.isEditInfo = true;
      this.$store.dispatch("getShopInfo");
    },
    // 打开我的海报
    myHaibao() {
      this.$refs.haibaoDialog.open();
    },
    // 签署入驻合同
    signFdd() {
      this.$refs.userInfoSure.open();
    },
    // 法大大认证
    fadadaAuth() {
      tenantqiyerenzheng({
        tenantId: this.userInfo.tenantId,
      }).then((res) => {
        console.log("%c Line:276 🍺 res", "color:#6ec1c2", res);
        if (res.msg && res.msg.incluse("http")) {
          window.open(res.msg);
          this.$alert("认证完成请点击确认！");
          this.$store.dispatch("getShopInfo", this.form.tenantId);
        }
      });
    },

    // 实名认证
    openAuth() {
      // if(this.shopInfo.authType==4){
      //   return
      // }
      this.$refs.authDialog.open();
    },

    // 获取保证金金额
    getBZJ() {
      this.getDicts("marginMoney").then((res) => {
        //console.log("%c Line:271 🥕 res", "color:#42b983", res);
        if (res.data && res.data.length) {
          this.BZJmoney = res.data[0].dictValue;
          this.BZJdes = res.data[0].remark
            ? res.data[0].remark.replace(/\n/g, "<br/>")
            : "";
        }
      });
    },
    getInfo() {
      this.$store.dispatch("getShopInfo", this.userInfo.tenantId);
      this.getTixianing();
    },
    mingxi(path) {
      this.$router.push({
        path: path,
      });
    },
    // 点击提现按钮
    tixianFn() {
      if (
        this.shopInfo.marginState == 2 &&
        this.shopInfo.marginMoney < this.BZJmoney
      ) {
        this.$message.error("保证金不足，请缴纳保证金后再提现！");
        return;
      }
      this.$refs.tixian.open(null);
    },
    // 点击充值
    chongzhijifen() {
      this.$refs.chongzhi.open();
      // this.$refs.paySuccess.open();
    },
    // 删除一个收款账户
    delItem(id) {
      this.$confirm("确认删除该提现账户吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          myMoneyApi.delBackcardListOne(id).then((res) => {
            this.$message.success(res.msg);
            this.getList();
          });
        })
        .catch(() => {});
    },
    // 查询已绑定的收款账户
    async getList() {
      let res1 = await myMoneyApi.getBackcardList({partyType:1});
      this.cardsList = res1.rows;
    },
    // 打开添加账户的弹窗
    addBackcard() {
      this.$refs.addBankcardDialog.open();
    },
    // 查询是否有正在提现的记录
    getTixianing() {
      myMoneyApi
        .withdrawalRecordList({ pageNum: 1, pageSize: 3, state: 1 })
        .then((res) => {
          if (res && res.rows.length && res.rows[0].state == 1) {
            this.TIXIANING = res.rows[0];
          } else {
            this.TIXIANING = "";
          }
        });
    },

    editUserInfo() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.isEditName = false;
          editShop(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.$store.dispatch("getShopInfo", this.form.tenantId);
            this.isEditInfo = false;
            this.centerDialogVisible = false;
          });
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },

    // LOGO上传成功
    avatarChange(e) {
      this.form.avatar = e;
    },

    // 营业执照上传成功
    businessLicenseImgChange(e) {
      // console.log("%c Line:309 🍐 e", "color:#3f7cff", e);
      this.form.businessLicenseImg = e;
    },

    // 取消修改
    cancelEdit() {
      this.form = JSON.parse(JSON.stringify(this.shopInfo));
      this.isEditInfo = false;
      this.centerDialogVisible = false;
    },
    // 打开缴纳保证金的窗口
    openPayBZJ() {
      const money =
        Math.round((this.BZJmoney - this.shopInfo.marginMoney) * 100) / 100;
      this.$refs.payBZJ.open(money, this.BZJmoney || 0);
    },
    // 打开保证金明细
    openBZJOrder() {
      this.$refs.BZJmingxi.open();
    },
    // 保证金提现
    openTixian() {
      this.$store.dispatch("getShopInfo");
      this.$refs.tixian.open(null, "bzj");
    },
  },
};
</script>

<style scoped lang="scss">
.form-box {
  margin-top: 30px;
  .tit {
    margin-bottom: 20px;
    .edit-btn {
      color: $acativeTxtColor;
      cursor: pointer;
    }
  }
  .btn-box {
    width: 100%;
    text-align: center;
  }
  .head-img {
    margin-right: 16px;
    position: relative;
    width: 75px;
    ::v-deep .el-upload {
      width: 75px;
      height: 75px;
      border: none;
      .btn {
        color: $fff;
      }
    }
    img {
      width: 100%;
      height: 75px;
      border-radius: 50%;
    }
    .btn {
      width: 100%;
      height: 18px;
      background-color: $primary;
      text-align: center;
      line-height: 18px;
      cursor: pointer;
      border-radius: 9px;
      position: absolute;
      bottom: 0;
    }
  }
}
</style>
